﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t402Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t402_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t402Mgr mgr = new t402Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t402(e.Parameters[t402_Filter.ParamPrefix]));
            IList<t402> list = mgr.FindAllByPage_t402(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t402_Filter.ParamPrefix]);
            t402_MainStore.DataSource = list;
            t402_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t402Mgr mgr = new t402Mgr();
            RowSelectionModel sm = t402_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t402 _t402 = new t402();
                _t402.t402_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t402(_t402))
                {
                    log.Debug("t402中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t402_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t402Mgr mgr = new t402Mgr();
            t402 _t402 = new t402();
            if (Hid.Text.Length > 0)
                _t402 = mgr.FindById_t402(int.Parse(Hid.Text));
            
			_t402.t402_01 = Txtt402_01.Text.Trim();
			_t402.t402_02 = Txtt402_02.Text.Trim();
			_t402.t402_03 = Txtt402_03.Text.Trim();
			_t402.t402_04 = Txtt402_04.Text.Trim();
			_t402.t402_05 = Txtt402_05.Text.Trim();
			_t402.t402_06 = Txtt402_06.Text.Trim();
			_t402.t402_07 = Txtt402_07.Text.Trim();
			_t402.t402_08 = Txtt402_08.Text.Trim();
			_t402.t402_09 = Txtt402_09.Text.Trim();
			_t402.t402_10 = Txtt402_10.Text.Trim();
			_t402.t402_11 = Txtt402_11.Text.Trim();
			_t402.t402_12 = Txtt402_12.Text.Trim();
			_t402.t402_13 = Txtt402_13.Text.Trim();
			_t402.t402_14 = Txtt402_14.Text.Trim();
			_t402.t402_15 = Txtt402_15.Text.Trim();
			_t402.t402_16 = Txtt402_16.Text.Trim();
			_t402.t402_17 = Txtt402_17.Text.Trim();
			_t402.t402_18 = Txtt402_18.Text.Trim();
			_t402.t402_19 = Txtt402_19.Text.Trim();
			_t402.t402_20 = Txtt402_20.Text.Trim();
			_t402.t402_21 = Txtt402_21.Text.Trim();
			_t402.t402_22 = Txtt402_22.Text.Trim();
			_t402.t402_23 = Txtt402_23.Text.Trim();
			_t402.t402_46 = Txtt402_46.Text.Trim();
			_t402.t402_24 = Txtt402_24.Text.Trim();
			_t402.t402_25 = Txtt402_25.Text.Trim();
			_t402.t402_26 = Txtt402_26.Text.Trim();
			_t402.t402_27 = Txtt402_27.Text.Trim();
			_t402.t402_28 = Txtt402_28.Text.Trim();
			_t402.t402_29 = Txtt402_29.Text.Trim();
			_t402.t402_30 = Txtt402_30.Text.Trim();
			_t402.t402_31 = Txtt402_31.Text.Trim();
			_t402.t402_32 = Txtt402_32.Text.Trim();
			_t402.t402_33 = Txtt402_33.Text.Trim();
			_t402.t402_34 = Txtt402_34.Text.Trim();
			_t402.t402_35 = Txtt402_35.Text.Trim();
			_t402.t402_36 = Txtt402_36.Text.Trim();
			_t402.t402_37 = Txtt402_37.Text.Trim();
			_t402.t402_38 = Txtt402_38.Text.Trim();
			_t402.t402_39 = Txtt402_39.Text.Trim();
			_t402.t402_40 = Txtt402_40.Text.Trim();
			_t402.t402_41 = Txtt402_41.Text.Trim();
			_t402.t402_42 = Txtt402_42.Text.Trim();
			_t402.t402_43 = Txtt402_43.Text.Trim();
			_t402.t402_44 = Txtt402_44.Text.Trim();
			_t402.t402_45 = Txtt402_45.Text.Trim();
			_t402.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t402(_t402);
            else
                isok = mgr.Add_t402(_t402);
            if (isok)
            {
                t402_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t402中执行了保存（插入或修改），并成功");
                t402_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}